package com.dtp.adapter.common;

import com.dtp.common.properties.DtpProperties;
import com.dtp.common.entity.TpExecutorProps;
import com.dtp.core.support.ExecutorWrapper;
import com.dtp.core.support.MetricsAware;
import org.slf4j.Logger;

import java.util.Collections;
import java.util.Map;

/**
 * 动态线程池适配器
 *
 * @author yanhom
 * @since 1.0.6
 *
 * @remark muse
 */
public interface DtpAdapter extends MetricsAware {

    /** 获取指定线程池执行器包装器（ExecutorWrapper）*/
    default ExecutorWrapper getExecutorWrapper() {return null;}

    /** 获得执行器包装器（ExecutorWrapper）集合 */
    default Map<String, ExecutorWrapper> getExecutorWrappers() {return Collections.emptyMap();}

    /** 使用指定的属性刷新线程池 */
    void refresh(DtpProperties dtpProperties);

    /** 检查更新参数 */
    default boolean containsInvalidParams(TpExecutorProps props, Logger log) {
        if (props.getCorePoolSize() < 0
                || props.getMaximumPoolSize() <= 0
                || props.getMaximumPoolSize() < props.getCorePoolSize()
                || props.getKeepAliveTime() < 0)
            return true;
        return false;
    }
}
